const Router = require("koa-router");
const { APP_PREFIX } = require("../config/config.default");
const {
  userValidator,
  verifyUsername,
  crpytPassword,
  verifyLogin,
} = require("../middleware/user.middleware");
const { auth } = require("../middleware/auth.middleware");
const {
  register,
  login,
  changePassword,
} = require("../controller/user.controller");

const router = new Router({ prefix: `/${APP_PREFIX}/users` });

// 注册接口
router.post(
  "/register",
  userValidator,
  verifyUsername,
  crpytPassword,
  register
);

// 登录
router.post("/login", userValidator, verifyLogin, login);

// 修改密码接口
router.patch("/", auth, crpytPassword, changePassword);

module.exports = router;
